//写进度条的实现
#include <stdio.h>
#include <unistd.h>
#include <string.h>

#define STYLE '#'
#define NUM 101
void ProcessBar(double current,double total)
{
    
    char buff[NUM];
    memset(buff,0,sizeof(buff));
    const char* lable = "|/-\\";
    size_t len = strlen(lable);
    static int flag = 0;
    //计算当前百分比
    size_t cnt = (size_t)(current*100/total);
    //对进度条进行修正
    for(int i = 0;i <= cnt;i++)
    {
        buff[i] = STYLE;
    }
    double rate = (current/total)*100;
    flag %= len;
    printf("[%-100s][%.2lf%%][%c]\r",buff,rate,lable[flag++]);
    fflush(stdout);
    printf("\r");
}






//void ProcessBar()
//{
//    printf("Test ProcessBar\n");
//    char buff[NUM];
//    memset(buff,0,sizeof(buff));
//    const char* lable = "|/-\\";
//    size_t len = strlen(lable);
//    for(int i = 0;i <= 100;i++)
//    {
//        printf("[%-100s][%d%%][%c]\r",buff,i,lable[i%len]);
//        fflush(stdout);
//        buff[i] = STYLE;
//        usleep(10000);
//    }
//    printf("\n");
//
//}
